package com.kd.spring.model;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class BeanLife implements BeanNameAware,ApplicationContextAware,InitializingBean,DisposableBean{
	private  String info;
	
	public BeanLife() {
		System.out.println("第一步：instintializate the bean 实例化Bean");
	}
	
	public void setInfo(String info) {
		System.out.println("第二步：封装属性  populate property：依赖注入bean的属性");
		this.info = info;
	}

	public String getInfo() {
		return info;
	}
	@Override
	public void setBeanName(String beanName) {
		System.out.println("第三步：如果实现了BeanNameAware：会注入配置文件中所配置的Bean的Id："+beanName);
	}
	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		// TODO Auto-generated method stub
		System.out.println("第四步：如果实现了ApplicationContextAware：会将整个Spring的上下文注入："+applicationContext);
	}
	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("第六步：属性设置完成");
	}
	public void init (){
		System.out.println("第七部：调用配置文件中初始化方法init ");
	}

	@Override
	public String toString() {
		System.out.println("第九步：业务处理");
		return "BeanLife [info=" + info + ", getInfo()=" + getInfo()
				+ ", toString()=" + super.toString() + "]";
	}
	@Override
	public void destroy() throws Exception {
		System.out.println("第十步：如果实现Disposabled方法，执行里面的destroy方法");
	}
	public void beanDestroy(){
		System.out.println("第十一步：实现配置文件中配置的method-destory方法");
	}
}
